﻿using Arch.EntityFrameworkCore.UnitOfWork;
using AutoMapper;
using Common.dto;

using WebApi.context;
using WebApi.model;

namespace WebApi.service;

public class ToDoTaskService:BaseService<ToDoTask>,IToDoTaskService
{
    private readonly ToDoTaskContext _toDoTaskContext;
    private readonly IMapper _mapper;

    public ToDoTaskService(IUnitOfWork<ToDoTaskContext> unitOfWork,ToDoTaskContext toDoTaskContext,IMapper mapper) : base(unitOfWork)
    {
        _toDoTaskContext = toDoTaskContext;
        _mapper = mapper;
    }

    public Page<ToDoTaskDto> Page(Page<ToDoTaskDto> query, ToDoTaskDto doTaskDto)
    {
        IQueryable<ToDoTaskDto> toDoTasks = from todo in _toDoTaskContext.ToDoTasks
                .Skip((query.Current-1)*query.Size)
                .Take(query.Size)
            select _mapper.Map<ToDoTaskDto>(todo);

        List<ToDoTaskDto> toDoTaskDtos = toDoTasks.ToList();
        return new Page<ToDoTaskDto>(toDoTaskDtos,query.Current,query.Size);
    }
}